package com.kotlin.flong.flow

import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.runBlocking

/**
 * @Author:liangjl
 * @Date: 2020/7/11-20:32
 * @Eamil:jilongliang@sina.com
 * @Description:
 * Flatten Flow
 */
private fun myMethod(i: Int): Flow<String> = flow {
    emit("$i :first")
    delay(500)
    emit("$i :second")

}

fun main() = runBlocking {
    var startTime = System.currentTimeMillis()

    (1..3).asFlow().onEach {
        delay(100L)
    }.flatMapConcat { myMethod(it) }
        .collect { value ->
            println("$value at ${System.currentTimeMillis() - startTime} ms")
        }


}